
import { GraphNode } from "@/js/components/GraphNode"
import { GraphView } from "@/js/components/GraphView"
import { InputLinkNodeAny, InputLinkNodeBoolean, InputLinkNodeColor, InputLinkNodeFlow, InputLinkNodeFunction, InputLinkNodeGroup, InputLinkNodeNumber, InputLinkNodeObject, InputLinkNodeString } from "@/js/components/InputLinkNode"

export class Function extends GraphNode{
    group?: InputLinkNodeGroup
    load(){
        super.load()

        const layout = new this.DefaultLayout(this, this.graphView as GraphView, true, true)
        this.layout = layout
        this.appendChild(layout.container)
        
        // 引用
        layout.main?.left.appendChild(new InputLinkNodeString(this, this.graphView as GraphView, {
            name: "funName", 
            desc: '函数名称',
            model: 'entry',
            placeholder: "函数名称",
            showLinkNode: false,
        }))

        // 引用
        layout.main?.right.appendChild(new InputLinkNodeFunction(this, this.graphView as GraphView, {
            name: "quote", 
            desc: '引用',
            model: "output",
            showInput: false,
        }))

        layout.main?.right.appendChild(new InputLinkNodeFlow(this, this.graphView as GraphView, {
            name: "body", 
            desc: '函数体',
            model: "output",
            showInput: false,
        }))

        const group = new InputLinkNodeGroup( this, this.graphView as GraphView , {
            name: 'arguments'
        })
        layout.main?.right.appendChild(group)
        group.addInputLinkNode("字符串(string)", InputLinkNodeString, {
            name: '',
            desc: '字符串(string)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            inputValue: '',
            isBindValue: false
        }).addInputLinkNode("数值(number)", InputLinkNodeNumber, {
            name: '',
            desc: '数值(number)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            isBindValue: false
        }).addInputLinkNode("布尔(boolean)", InputLinkNodeBoolean, {
            name: '',
            desc: '布尔(boolean)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            isBindValue: false
        }).addInputLinkNode("对象(object)", InputLinkNodeObject, {
            name: '',
            desc: '对象(object)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            isBindValue: false
        }).addInputLinkNode("函数(function)", InputLinkNodeFunction, {
            name: '',
            desc: '函数(function)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            isBindValue: false
        }).addInputLinkNode("通用(any)", InputLinkNodeAny, {
            name: '',
            desc: '通用(any)',
            model: "output",
            inputTypeString: true,
            placeholder: '变量名称',
            isBindValue: false
        })
        .layout?.alignItems('flex-end')
        this.group = group
    }

    import(obj:any){
        this.group?.import(obj.userData.arguments)
        super.import(obj)
    }
}